%!TEX root = report.tex


\section{Introduction }
\label{sec:intro}

Model-based software engineering (MBSE) is widely used nowadays for creating embedded software. 
As any other approach, it has its strong and weak sides, and thus might not be suitable for the whole domain of embedded software systems. 
Some may argue against using of MBSE, while others may disagree with them. 
We did want to have a better understanding of MBSE approaches and agreed that the only thing that might give it to us is our experience.
To gain such experience, we developed a solution to a simple but real-life problem. 
Having both the knowledge from the course and this experience, we hope that we will be able to answer the question whether a particular problem should be solved using MBSE or not. 

We decided to work on the proposed family of software systems for simple bicycle computers~\cite{atlee:projDef}. 
Although it might not sound like a huge and important problem, it is big enough to make us gain experience in key aspects of MDE such as creating domain specific language (DSL) and code generation. 
At the same time, the problem is not too big to prevent us from completing it in a strict timeframe of a course project. 

The bicycle computer contains a display and two buttons (Fig.~\ref{fig:computer}). 
Each second the computer receives a number of wheel rotations in the last second. 
Using this value as well as a circumference of the wheel, the computer calculates the values of mode functions. 
The display shows the current speed, the name of current mode, and the value of this mode. 
Mode button changes the current mode to the next one; if the last mode is selected, the next mode is the first one. 
Start/stop button resumes or pauses the calculations. 
Mode functions might be standalone expressions or use the values of other mode functions (e.g., AverageSpeed = Distance/ElapsedTime)

To gain experience in developing domain specific languages we chose a tool called Xtex\footnote{http://www.eclipse.org/Xtext/} that is used for creating textual DSLs. 
This choice was driven by our personal preferences.
Although there are some other tools (e.g., GMF~\cite{www:gmf}, MetaEdit+~\cite{www:metaedit}) that use graphical notation, we are more comfortable with thinking about a DSL as a little programming language~\cite{Bentley:littleLanguages} and thus as something implemented in a textual form. 
From this experience we want to be able to answer some questions: 
\begin{enumerate}
	\item How hard is it to create a new DSL?	
	\item What kind of knowledge is crucial for using Xtext?
\end{enumerate}

However, creating a domain specific language is only one of mandatory steps to complete software. 
Having a ``program" expressed in our little language we need to generate a source code that can be compiled or used for compilation of the software. 
To do this step we used a tool called Xtend\footnote{http://www.eclipse.org/Xtext/\#xtend2} that might be used for code generation. 
Xtend is tightly bundled with Xtext, and uses output from Xtext and user-defined string templates to produce source code. 
Although Xtend is implemented in Java, it can produce source code for any language. 
We tried to find the answers to similar questions:
\begin{enumerate}
	\item Does Xtend require an end user with a specific knowledge?
	\item How hard is to create a code generator using Xtend?
\end{enumerate}

When we apply a code generator that we created using Xtend to code expressed in our little language, we receive Java source code files.  
However, these files contain only one part of bicycle computer functionality, and we needed to create a framework of a bicycle computer that can incorporate them and be compiled into complete software. 
We developed the framework in Java using AWT and SWING libraries. 

The remainder of the report is as follows. 
A brief overview of the technologies we used is provided in Section~\ref{sec:technologies}. 
The domain specific language that we created is presented in Section~\ref{sec:dsl}. 
The code generation is described in Section~\ref{sec:transformation}. 
Our framework is covered in Section~\ref{sec:framework}.
Our experience is included in Section~\ref{sec:exp}; Section~\ref{sec:conclusion} concludes the report.

\begin{figure}
	\includegraphics[width=1.0\columnwidth]{imgs/bicycle_computer_desc.png}
	\caption{The UI of a simple bicycle computer}
	\label{fig:computer}
\end{figure} 

